package com.lujianfei.powersearch.utils;

import android.util.Log;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ConfigUtils {

    private static final String TAG = "ConfigUtils";
    public static List<ConfigEntity> loadConfig(){
        List<ConfigEntity> configEntities = new ArrayList<>();
        String assetContent = AssetUtils.getAssetContent("config.json");
        try {
            JSONObject jsonObject = new JSONObject(assetContent);
            JSONArray inputWidgets = jsonObject.optJSONArray("inputWidgets");
            for (int i = 0; i < inputWidgets.length(); i++) {
                JSONObject jsonObject1 = inputWidgets.optJSONObject(i);
                ConfigEntity configEntity = new ConfigEntity();
                configEntity.name = jsonObject1.optString("name");
                configEntity.className = jsonObject1.optString("className");
                configEntities.add(configEntity);
            }
            return configEntities;
        } catch (Exception e) {
            Log.e(TAG,""+e);
        }
        return configEntities;
    }
    public static class ConfigEntity implements Serializable {
        String name;
        String className;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getClassName() {
            return className;
        }

        public void setClassName(String className) {
            this.className = className;
        }
    }
}
